﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GISCore.Geometry
{
    [Serializable]
    public class Point : IComparable, IEquatable<Point>
    {
        private double x;
        private double y;

        //Constructor
        public Point(double x, double y)
        {
            this.x = x;
            this.y = y;
        }

        public static Point operator +(Point a, Point b)
        {
            return new Point(a.x + b.x, a.y + b.y);
        }

        public static Point operator *(Point a, double d)
        {
            return new Point(a.x * d, a.y * d);
        }

        public override string ToString()
        {
            return string.Format("X: {0} Y: {1}", x, y);
        }

        public override int GetHashCode()
        {
            int hash = 13;
            hash = (hash * 7) + x.GetHashCode();
            hash = (hash * 7) + y.GetHashCode();
            return hash;
        }

        public override bool Equals(object obj)
        {
            Point p = obj as Point;
            return (p != null) && (this.x == p.x && this.y == p.y);
        }

        public int CompareTo(object obj)
        {
            Point Compare = (Point)obj;
            int result;
            if (this.X != Compare.X)
            {
                result = this.X.CompareTo(Compare.X);
            }
            else
            {
                result = this.Y.CompareTo(Compare.Y);
            }
            return result;
        }

        public bool Equals(Point other)
        {
            return (other != null) && 
                   (other.X == this.X && other.Y == this.Y);
        }

        //Setter and Getter

        public double X
        {
            get { return x; }

        }

        public double Y
        {
            get { return y; }

        }

        public double getX()
        {
            return x;
        }

        public double getY()
        {
            return y;
        }


        public void setX(double x1)
        {
            x=x1;
        }

        public void setY(double y1)
        {
            y = y1;
        }

        public static double GetLineLength(Point pt1, Point pt2)
        {
            return Math.Sqrt((pt1.X - pt2.X) * (pt1.X - pt2.X) + (pt1.Y - pt2.Y) * (pt1.Y - pt2.Y));
        }
        
    }
}
